use std::path::PathBuf;

use argh::FromArgs;

use crate::context;
use crate::errors::Error;

pub mod init;
pub mod update;

#[derive(Debug, PartialEq, FromArgs)]
#[argh(description = "aspect protocol CLI utility")]
pub struct Args {
    #[argh(option, description = "user data directory")]
    pub datadir: Option<PathBuf>,

    #[argh(subcommand)]
    pub subc: Subcommand,
}

#[derive(Debug, PartialEq, FromArgs)]
#[argh(subcommand)]
pub enum Subcommand {
    Init(init::Args),
    Update(update::Args),
}

pub fn exec_subc(subc: Subcommand, ctx: context::Context) -> Result<(), Error> {
    match subc {
        Subcommand::Init(args) => init::exec(args, ctx),
        Subcommand::Update(args) => update::exec(args, ctx),
    }
}
